import { Subscription, Reducer, Effect } from 'umi';

const namespace = 'Example';

export interface ExampleStateType {
  user: {
    id?: number;
    name?: string;
  };
}

export interface ModelType {
  namespace: string;
  state: ExampleStateType;
  subscriptions?: { setup: Subscription };
  effects: {
    // 动态添加effects中定义的类型
    [key: string]: Effect;
  };
  reducers: {
    // 动态添加reducers中定义的类型
    [key: string]: Reducer<ExampleStateType>;
  };
}

const Model: ModelType = {
  namespace,
  state: {
    user: {
      name: 'codvision',
    },
  },
  subscriptions: {
    setup({ history }) {
      history.listen((location) => {
        console.log(location);
      });
    },
  },
  effects: {},
  reducers: {},
};
export default Model;
